import sqlite3
conn = sqlite3.connect('../database.db')
conn.row_factory = sqlite3.Row

sql = 'CREATE TABLE IF NOT EXISTS "main"."gate_pass_info_index" ("secret_card" text(30), "table_index" INTEGER)'

conn.execute(sql)
conn.commit()

with open('../index_result.txt', 'r', encoding='utf8') as f:
    total = 0
    for line in f:
        line_split = line.split('=')
        if len(line_split[0]) < 5:
            continue
        secret_card = line_split[0]
        index = int(line_split[1])
        start_char = secret_card[0]
        sql = "insert into gate_pass_info_index_{}(secret_card, table_index) values('{}', {})".format(start_char, secret_card, index)
        conn.execute(sql)
        total += 1
        if total % 100000 == 0:
            print('total is {}, commit'.format(total))
            conn.commit()

conn.close()